'use strict';

/**
 * @name SpaceListCtrl
 * @author ZYF
 */

angular.module('metalabOperationApp').controller('SpaceListCtrl', ['$scope', '$rootScope', '$state', '$stateParams', 'MetaResources', 'MetaRemind', 'MetaFilter', 'MetaSearch', 'MetaSort', 'MetaUtils', function ($scope, $rootScope, $state, $stateParams, MetaResources, MetaRemind, MetaFilter, MetaSearch, MetaSort, MetaUtils) {
    $scope.listCtrl = {
        filterConfig: ['disciplineClass', 'discipline'],
        filterParams: {},
        searchConfig: {
            organization_like: '机构',
            department_like: '部门',
            phone_like: '手机',
        },
        searchParams: {},
        sortParams: '-created_at',
        tableParams: {}
    };
    $scope.init = function () {
        MetaUtils.initListCtrl($scope, $stateParams);
    };
    $scope.getListData = function (page) {
        var queryParams = {
            '_embed': 'user',
            '_sort': '',
            '_range': '',
            'disciplineClass': '',
            'discipline': ''
        };
        var dynamicQueryParams = [];
        MetaUtils.buildQueryParams(page, queryParams, dynamicQueryParams, $scope.listCtrl, $stateParams);
        MetaResources.talent.query(
            queryParams,
            function (data, header) {
                MetaUtils.receiveListData($scope.listCtrl, $stateParams, page, data, header);
            },
            function (error) {
                MetaRemind.serverError(error);
            });
    };
    $scope.changeUrl = function (type) {
        var urlParams = {
            page: $scope.listCtrl.tableParams.currentPage,
            sort: $scope.listCtrl.sortParams,
            showAll: $scope.listCtrl.tableParams.isShowAll
        };
        MetaFilter.encodeURLFilterParams(urlParams, $scope.listCtrl.filterParams);
        MetaSearch.encodeUrlSearchParams(urlParams, $scope.listCtrl.searchParams);
        if (type==='disciplineClass') {
          urlParams.discipline = "所有学科";
        }
        $state.go('meta.permission.research.space.list', urlParams);
    };
    $scope.init();
}]);
